<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>整机故障率</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../css/style.css">
	<script type="text/javascript" src="../../js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="../../js/dialog/jquery.artDialog.source.js?skin=default"></script>
	<script type="text/javascript" src="../../js/dialog/plugins/iframeTools.source.js"></script>
	<script type="text/javascript" src="../../js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/charts/highcharts.js"></script>
	<script type="text/javascript" src="../../js/charts/modules/exporting.js"></script>
	<script type="text/javascript" src="../../js/jquery.form.js"></script>
	<script type="text/javascript" src="../../js/jquery.page.js"></script>
	<script type="text/javascript" src="../../js/base.js"></script>
	<script type="text/javascript">
	$(function(){
		$('select[name=adminCode]').selectload('../../common/adminunit_select.action','adminCode','adminName');
		$('select[name=propertyCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName');
		$('select[name=serviceCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName');
		$(document).mouseup(function(e){
			var $target = $(e.target);
			if(!$target.is('.areaTree')){
				if($target.parents('.areaTree').length == 0){
					$('.areaTree').hide();
				}
			}
		});
		//渲染区域树
		$.fn.zTree.init($('#areaTree'),{
			data: {
				key:{
					name:'areaname'
				},
				simpleData: {
					enable: true,
					idKey:'areacode',
					pIdKey:'parentcode',
					rootPId:0
				}
			},
			async: {
				enable: true,
				url:"../../common/area_tree.action",
				autoParam:["areacode"]
			},
			callback:{
				onClick:function(e,id,node){
					var oldnode = node;
					if(node.isParent == false){
						var $areaTree = $('.areaTree');
						var areaArr = new Array();
						areaArr.unshift(node.areaname);
						while(node.parentcode > 0){
							node = node.getParentNode();
							areaArr.unshift(node.areaname);
						}
						$('input[name=areaNameN]').val(areaArr.join(' > '));
						$('input[name=areaName]').val(oldnode.areacode);
						$areaTree.hide();
					}
				}
			}
		});
		
		//区域树
		$('input[name=areaNameN]').click(function(){
			$this = $(this);
			$hidden = $('input[name=areaName]');
			$areaTree = $('.areaTree');
			$this.val('');
			$hidden.val('');
			var os = $this.offset();
			$areaTree.css({left:os.left,top:os.top+($this.outerHeight(true)-1)});
			$areaTree.show();
		});
		$('#list').page({
			url:'zjgzl_search.action',
			config:'pageinfo,record,first,last,next,prev,jump',
			items:[{
				title:'电梯号码',
				name:'eleCode'
			},{
				title:'电梯名称',
				name:'eleName'
			},{
				title:'统计时限',
				render:function(row){
					return row.runDateMin+' 至 '+row.runDateMax;
				}
			},{
				title:'运行次数',
				name:'eleRunDegree',
				irender:function(row){
					return row.eleRunDegree > 0 ? row.eleRunDegree : 0;
				}
			},{
				title:'故障次数',
				name:'faultCount'
			},{
				title:'故障率',
				render:function(row){
					var eleRunDegree = row.eleRunDegree > 0 ? row.eleRunDegree : 0;
					var faultRate = row.faultCount/eleRunDegree*100;
					return faultRate.toFixed(2)+'%';
				}
			},{
				title:'详情',
				render:function(row){
					$a = $('<a href="javascript:void(0)")">【详细】</a>');
					$a.click(function(){
						$.post('../../common/area_name.action',{areacode:row.areaName},function(data){
							var eleRunDegree = row.eleRunDegree > 0 ? row.eleRunDegree : 0;
							var faultRate = row.faultCount/eleRunDegree*100;
							$(row).attr('faultRate',faultRate.toFixed(2)+'%');
							$(row).attr('areaNameN',data);
							$(row).attr('timeTJ',row.runDateMin+' 至 '+row.runDateMax);
							view(row);
						},'text');
					});
					return $a;
				}
			}]
		});
		$('#search').ajaxForm({
			beforeSubmit:function(formData){
				var param = $(formData).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				return false;
			}
		});
		$('#btnExcel').click(function(){
			var s = document.search
			var para = {
				'k':'zjgzl',
				'adminCode':s.adminCode.value,
				'propertyCode':s.propertyCode.value,
				'serviceCode':s.serviceCode.value,
				'eleCode':s.eleCode.value,
				'timeRange':s.timeRange.value,
				'areaName':s.areaName.value
			}
			window.location.href="../../common/excel_io.action?"+$.param(para);
		});
	});

	var view = function(row){
		$.post('zjgzl_view.action',{eleCode:row.eleCode,timeRange:document.search.timeRange.value},function(data){
			var bind = [];
			$('label[name=faultTypes]').html('0');
			$.each(data,function(i,n){
				bind[i] = {name:n.codedesc,y:n.number}
				$('label[t='+n.codedesc+']').html(n.number);
			});
			$('#container').highcharts({
	            chart: {
	                plotBackgroundColor: null,
	                plotBorderWidth: null,
	                plotShadow: false
	            },
	            title: {
	                text: row.runDateMin+' 至 '+row.runDateMax+' 整机故障率统计'
	            },
	            plotOptions: {
	                pie: {
	                    allowPointSelect: true,
	                    cursor: 'pointer',
	                    dataLabels: {
			            	enabled: true,
		                    color: '#000000',
		                    connectorColor: '#000000',
		                    formatter: function() {
		                        return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %';
		                    }
	                    },
	                    showInLegend: true
	                }
	            },
	            legend:{
	            	layout: 'vertical',
	            	align: 'right',
	            	verticalAlign: 'middle',
	            	borderWidth: 1,
	            	itemMarginBottom:3
		        },
	            series: [{
	                type: 'pie',
	                name: '次数',
	                data: bind
	            }]
	        });
			$.dialog({
				id:'viewdialog',
				title:'信息查看-整机故障率',
				lock:true,
				width:'100%',
				height:'100%',
				content:document.getElementById('view')
			});
			$('#viewForm').json2form(row);
			
		},'json');
		
	}


	$(function(){
		 
	})
	</script>
</head>
<body class="app">
	<h3>整机故障率</h3>
	<form class="search" id="search" name="search" method="post">
		<div class="tbdiv">
		<table>
			<tr>
				<th width="100">行政监管单位：</th>
				<td width="100"><select name="adminCode"></select></td>
				<th width="100">物业公司：</th>
				<td width="100"><select name="propertyCode"></select></td>
				<th width="100">维保单位：</th>
				<td><select name="serviceCode"></select></td>
			</tr>
			<tr>
				<th width="100">电梯号码：</th>
				<td width="100"><input type="text" class="inputText" name="eleCode" value="" style="width:100px;"/></td>
				<th width="100">统计时限：</th>
				<td colspan="3">
					<select name="timeRange" style="width:75px;">
					<option value="">全部</option>
					<option value="2">近一周</option>
					<option value="3">近一个月</option>
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="6">
					<table>
						<tr>
							<th width="99">所属区域：</th>
							<td>
								<input type="hidden" name="areaName" value=""/>
								<input type="text" class="inputText" name="areaNameN" value="" style="width:347px;*width:348px;cursor:pointer;" readonly="readonly" />
							</td>
							<td><input type="submit" value="查询" class="inputButton"/></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</div>
	</form>
	<div id="list"></div>
	<div class="optionlink">
		<span id="btnPrint">【打印】</span>
		<span id="btnExcel">【导出Excel】</span>
	</div>
	<div class="areaTree"><div id="areaTree" class="ztree"></div></div>
	
	<div id="view" style="display:none;">
		<div id="container" style="height:350px; margin: 0 auto"></div>
		<form id="viewForm" name="viewForm">
		<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="1" class="table2">
		    <tr>
		      <td width="18%" align="right" class="bg_title" >电梯号码：</td>
		      <td width="31%" class="bg_title2" ><label name="eleCode"></label></td>
		      <td width="19%" align="right" class="bg_title" >电梯名称：</td>
		      <td width="32%" class="bg_title2" ><label name="eleName"></label></td>
		    </tr>
		    <tr>
		      <td align="right" class="bg_title" >注册代码：</td>
		      <td align="left" class="bg_title2" ><label name="eleBasicRegNum"></label></td>
		      <td align="right" class="bg_title" >所属区域：</td>
		      <td align="left" class="bg_title2" ><label name="areaNameN"></label></td>
		      
		    </tr>
		    <tr>
		      <td align="right" class="bg_title" >行政监管单位：</td>
		      <td align="left" class="bg_title2" ><label name="adminName"></label></td>
		      <td align="right" class="bg_title" >物业公司：</td>
		      <td align="left" class="bg_title2" ><label name="propertyName"></label></td>
		    </tr>
		    <tr>
		      <td align="right" class="bg_title" >维保单位：</td>
		      <td align="left" class="bg_title2" ><label name="serviceName"></label></td>
		      <td align="right" class="bg_title" > 总运行次数：</td>
		      <td align="left" class="bg_title2" ><label name="eleRunDegree"></label></td>
		    </tr>
		    <tr>
		      <td align="right" class="bg_title" >总故障次数：</td>
		      <td align="left" class="bg_title2" ><label name="faultCount"></label></td>
		      <td align="right" class="bg_title" >故障率：</td>
		      <td align="left" class="bg_title2" ><label name="faultRate"></label></td>
		    </tr>
		    <tr>
		      <td align="right" class="bg_title" >安全回路故障：</td>
		      <td class="bg_title2" ><label name="faultTypes" t="安全回路故障"></label></td>
              <td align="right" class="bg_title" >停车门故障：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="停车门故障"></label></td>
		      
		    </tr>
		    <tr align="center">
		      <td align="right" class="bg_title" > 上行门故障：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="上行门故障"></label></td>
		      <td align="right" class="bg_title" >下行门故障：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="下行门故障"></label></td>
		    </tr>
		    <tr align="center">
		      <td align="right" class="bg_title" >冲顶：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="冲顶"></label></td>
		      <td align="right" class="bg_title" >蹲底：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="蹲底"></label></td>
		    </tr>
		    <tr align="center">
		      <td align="right" class="bg_title" >关人：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="关人"></label></td>
		      <td align="right" class="bg_title" >超速：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="超速"></label></td>
		    </tr>
		    <tr align="center">
		      <td align="right" class="bg_title" >运行超时：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="运行超时"></label></td>
		      <td align="right" class="bg_title" >停电：</td>
		      <td align="left" class="bg_title2" ><label name="faultTypes" t="停电"></label></td>
		    </tr>
		    <tr align="center">
		      <td align="right" class="bg_title" >统计时限：      </td>
		      <td align="left" class="bg_title2" ><label name="timeTJ"></label></td>
		      <td align="right" class="bg_title" >操作：</td>
		      <td align="left" class="bg_title2" >
		        <input name="Submit3" class="inputButton" type="submit" value="打印" />
		      </td>
		    </tr>
		</table>
		</form>
	</div>
</body>
</html>
